<?php

namespace App\Models;

class OpenPrizeModel
{
    /**
     * 获取最新一条
     * return Array
     * */
    public static function getOpenPrizeInside($conn){
        $querySql="SELECT `id`,`sn`,`state`,`time`,`end_time`,`buy_num`,`winning_num`,`total`,`av`,`number` FROM `open_prize` order by `id` desc limit 1";
        return $conn->readConn($querySql);
    }
    /**
     * 获取最新一条开奖
     * return Array
     * */
    public static function getLastOpenPrizeInside($conn){
        $querySql="SELECT `id`,`sn`,`state`,`time`,`end_time`,`buy_num`,`winning_num`,`total`,`av`,`number` FROM `open_prize` where `state` = 1 order by `id` desc limit 1";
        return $conn->readConn($querySql);
    }
    /**
     *
     * return Array
     * */
    public static function getOpenPrizeInsideInSn($conn,$sn){
        $querySql="SELECT `id`,`sn`,`state`,`time`,`end_time`,`buy_num`,`winning_num`,`total`,`av`,`number` FROM `open_prize` where `sn` = '$sn'";
        return $conn->readConn($querySql);
    }
    /**
     * 更新参与人数
     * return Array
     * */
    public static function editOpenPrizeBuyNum($conn,$OpenPrizeExample){
        $querySql="UPDATE `open_prize` SET `buy_num` = `buy_num` + 1 where sn = '$OpenPrizeExample->sn' and `state` = $OpenPrizeExample->state and `buy_num` = $OpenPrizeExample->buy_num";
        return $conn->executeConn($querySql);
    }
    /**
     * 编辑奖池信息
     * entry $WithdrawExample
     * return int
     * */
    public static function upOpenPrizeInside($conn,$Example){
        $joinSql="";
        if($Example->time !=null){
            $joinSql.=" `time` = '$Example->time',";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `open_prize` SET $innerJoin WHERE `id` =$Example->id";
            return $conn->executeConn($upUserSql);
        }
    }
}